home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / cucd / prog / mui / modula / txt / muiclasssupport.mod < prev    next >
Text File  |  1996-08-14  |  8KB  |  262 lines

  1. IMPLEMENTATION MODULE MuiClassSupport ;
  2.  
  3. (****** MuiClassSupport/---information--- ************************************
  4. *
  5. *   VERSION
  6. *        $Id: MuiClassSupport.mod 1.4 1996/08/14 01:39:07 olf Exp olf $
  7. *
  8. *   COPYRIGHT
  9. *        written and (c) 1996 by Olaf 'Olf' Peters
  10. *
  11. *        report bugs, suggestions, comments to
  12. *
  13. *          olf@informatik.uni-bremen.de
  14. *          op@hb2.maus.de (no mail larger than 16 KB to this address!)
  15. *
  16. ******************************************************************************
  17. *
  18. *)
  19.  
  20. (*$ LargeVars := FALSE Volatile := FALSE *)
  21.  
  22. FROM SYSTEM     IMPORT  ADDRESS, ADR, LONGSET, TAG ;
  23. FROM AmigaLib   IMPORT  DoSuperMethodA, SetSuperAttrsA ;
  24.  
  25. IMPORT
  26.     mc : MuiClasses,
  27.     md : MuiD,
  28.     ml : MuiL,
  29.  
  30.     ed : ExecD,
  31.     el : ExecL,
  32.     id : IntuitionD,
  33.     il : IntuitionL,
  34.  
  35.     ud : UtilityD ;
  36.  
  37. (****** MuiClassSupport/DoSuperNew *******************************************
  38. *
  39. *   NAME
  40. *        DoSuperNew - create an instance of your superclass.
  41. *
  42. *   SYNOPSIS
  43. *        DoSuperNew(cl       : IClassPtr;
  44. *                   obj      : ObjectPtr ;
  45. *                   attrList : TagItemPtr) : ADDRESS ;
  46. *
  47. *   FUNCTION
  48. *        calls the OM_NEW method for the superclass to create an instance
  49. *        of your custom-class. Most likely you will call this in the
  50. *        NEW-Method of your customclass.
  51. *
  52. *   INPUTS
  53. *        cl       - a pointer to a customclass structure, if DoSuperMethod
  54. *                   ist called from the NEW method of your customclass, use
  55. *                   the ClassPtr you got as parameter for your NEW method.
  56. *
  57. *        obj      - also use the ObjectPtr you got as parameter for your
  58. *                   NEW method.
  59. *
  60. *        attrList - a taglist to set attributes of the superclass your
  61. *                   customclass is an instance of.
  62. *
  63. *   RESULT
  64. *        an instance of your customclass.
  65. *
  66. *   SEE ALSO
  67. *        amiga.lib/DoSuperMethodA
  68. *
  69. ******************************************************************************
  70. *
  71. *)
  72.  
  73. (*/// "DoSuperNew(cl : id.IClassPtr; obj : id.ObjectPtr ; attrList : ud.TagItemPtr) : ADDRESS" *)
  74.  
  75. PROCEDURE DoSuperNew(cl : id.IClassPtr; obj : id.ObjectPtr ; attrList : ud.TagItemPtr) : ADDRESS ;
  76.  
  77. VAR
  78.   opSet : id.OpSet ;
  79.  
  80. BEGIN
  81.   opSet.methodID := id.omNEW ;
  82.   opSet.attrList := attrList ;
  83.   opSet.gInfo := NIL ;
  84.  
  85.   RETURN DoSuperMethodA(cl, obj, ADR(opSet)) ;
  86. END DoSuperNew ;
  87.  
  88. (*\\\*)
  89.  
  90. (****** MuiClassSupport/setSuper *********************************************
  91. *
  92. *   NAME
  93. *        setSuper -- set attribute of a superclass
  94. *
  95. *   SYNOPSIS
  96. *        setSuper(cl     : IClassPtr ;
  97. *                 obj    : ObjectPtr ;
  98. *                 attr   : LONGCARD ;
  99. *                 value  : LONGINT) ;
  100. *
  101. *   FUNCTION
  102. *        Set an attribute of the superclass of an object.
  103. *
  104. *   INPUTS
  105. *        cl    - pointer to the customclass structure of your class.
  106. *        obj   - pointer to the instance of your customclass on which's
  107. *                superclass the attribute should be set.
  108. *        attr  - the attribute of your superclass to be set
  109. *        value - the attribute value
  110. *
  111. *
  112. *   SEE ALSO
  113. *        amiga.lib/SetSuperAttrs
  114. *
  115. ******************************************************************************
  116. *
  117. *)
  118.  
  119.  
  120. (*/// "setSuper(obj : id.ObjectPtr; attr : LONGCARD; value : LONGINT)" *)
  121.  
  122. PROCEDURE setSuper(cl : id.IClassPtr ; obj : id.ObjectPtr; attr : LONGCARD; value : LONGINT) ;
  123.  
  124. VAR
  125.   dummy : ADDRESS ;
  126.   tags  : ARRAY [0..3] OF LONGINT ;
  127.  
  128. BEGIN
  129.   dummy := SetSuperAttrsA(cl, obj, TAG(tags, attr, value, ud.tagDone)) ;
  130. END setSuper ;
  131.  
  132. (*\\\*)
  133.  
  134. (****** MuiClassSupport/InitClass ********************************************
  135. *
  136. *   NAME
  137. *        InitClass -- init MUI-CustomClass structure
  138. *
  139. *   SYNOPSIS
  140. *        InitClass(VAR mcc        : mCustomClassPtr;
  141. *                      base       : LibraryPtr ;
  142. *                      supername  : StrPtr ;
  143. *                      supermcc   : mCustomClassPtr ;
  144. *                      datasize   : LONGINT ;
  145. *                      dispatcher : DispatcherDef) : BOOLEAN ;
  146. *
  147. *   FUNCTION
  148. *        Easily allocate and initialize a MUI-CustomClass structure.
  149. *
  150. *        Be sure to call RemoveClass when you're done with the class (most
  151. *        likely InitClass() will be called from the startup-code of a
  152. *        module whereas RemoveClass will be called from the closing code.)
  153. *
  154. *   INPUTS
  155. *        mcc        -
  156. *
  157. *                     the structure to be initialized. It will also be
  158. *                     allocated for you, so be sure to not handle a valid
  159. *                     pointer to InitClass(), it will be overwritten!
  160. *        base,
  161. *        supername,
  162. *        supermcc,
  163. *        datasize   - see muimaster.library/MUI_CreateCustomClass
  164. *        dispatcher - this is the dispatcher function of your customclass,
  165. *                     it must match the following prototype:
  166. *
  167. *                     PROCEDURE ( (* class   *) id.IClassPtr,
  168. *                                 (* object  *) ADDRESS,
  169. *                                 (* message *) ADDRESS) : ADDRESS;
  170. *
  171. *                     No need to call MakeDispatcher as InitClass does this
  172. *                     for you.
  173. *
  174. *   RESULT
  175. *        TRUE if the initialization was successful, FALSE otherwise
  176. *
  177. *   EXAMPLE
  178. *        IMPLEMENTATION MODULE TestClass ;
  179. *
  180. *        [...]
  181. *
  182. *        BEGIN
  183. *          IF NOT (InitClass(class1, NIL, ADR(mcPopobject), NIL,
  184. *                            SIZE(Class1Data), Class1Dispatcher) AND
  185. *                  InitClass(class2, NIL, NIL,              class1,
  186. *                            SIZE(Class2Data), Class2Dispatcher)) THEN
  187. *            [Fail]
  188. *          END ;
  189. *        CLOSE
  190. *          RemoveClass(class2) ;
  191. *          RemoveClass(class1) ;
  192. *        END TestClass .
  193. *
  194. *        This will create the to classes class1 and class2 where class1 is
  195. *        a subclass of mcPopobject and class2 is a subclass of class1.
  196. *
  197. *   SEE ALSO
  198. *        MuiClassSupport/RemoveClass
  199. *        muimaster.library/MUI_CreateCustomClass
  200. *
  201. ******************************************************************************
  202. *
  203. *)
  204.  
  205. (*/// "InitClass(mcc, base, supername, supermcc, datasize, dispatcher) : BOOLEAN" *)
  206.  
  207. PROCEDURE InitClass(VAR mcc        : mc.mCustomClassPtr;
  208.                         base       : ed.LibraryPtr ;
  209.                         supername  : md.StrPtr ;
  210.                         supermcc   : mc.mCustomClassPtr ;
  211.                         datasize   : LONGINT ;
  212.                         dispatcher : mc.DispatcherDef) : BOOLEAN ;
  213. BEGIN
  214.   mcc := ml.moCreateCustomClass(base, supername, supermcc, datasize, NIL) ;
  215.   IF mcc = NIL THEN RETURN FALSE END ;
  216.   mc.MakeDispatcher(dispatcher, mcc^.class) ;
  217.   RETURN TRUE ;
  218. END InitClass ;
  219.  
  220. (*\\\*)
  221.  
  222. (****** MuiClassSupport/RemoveClass ******************************************
  223. *
  224. *   NAME
  225. *        RemoveClass - dispose of a MUI-CustomClass
  226. *
  227. *   SYNOPSIS
  228. *        RemoveClass(VAR mcc : mCustomClassPtr) ;
  229. *
  230. *   FUNCTION
  231. *        dispose of aMUI-CustomClass that has been initialised with
  232. *        InitClass()
  233. *
  234. *   INPUTS
  235. *        mcc - the customclass to dispose of, may also be NIL.
  236. *
  237. *        Note that this is a VAR parameter, it will be set to NIL after the
  238. *        call, so it is safe to call RemoveClass() more often on the same
  239. *        structure without any bad results.
  240. *
  241. *   SEE ALSO
  242. *        MuiClassSupport/InitClass
  243. *
  244. ******************************************************************************
  245. *
  246. *)
  247.  
  248. (*/// "RemoveClass(VAR mcc : mc.mCustomClassPtr)" *)
  249.  
  250. PROCEDURE RemoveClass(VAR mcc : mc.mCustomClassPtr) ;
  251. BEGIN
  252.   IF mcc # NIL THEN
  253.     IF ml.moDeleteCustomClass(mcc) THEN END ;
  254.     mcc := NIL ;
  255.   END (* IF *) ;
  256. END RemoveClass ;
  257.  
  258. (*\\\*)
  259.  
  260. END MuiClassSupport.
  261.  
  262.